#include <iostream>
#include <vector>
#include <string>

using namespace std;

// 速度较快
string complexNumberMultiply(string num1, string num2) {
    int a1, b1, a2, b2;
    sscanf(num1.c_str(), "%d+%di", &a1, &b1);
    sscanf(num2.c_str(), "%d+%di", &a2, &b2);
    
    int aa = a1 * a2 - b1 * b2;
    int bb = a1 * b2 + a2 * b1;
    
    return string(to_string(aa) + "+" + to_string(bb) + "i");
}

string mycomplexNumberMultiply(string num1, string num2) {
    int num1S = num1.find('+'), num2S = num2.find('+');
    num1.pop_back(); num2.pop_back();
    int num1R = stoi(num1.substr(0, num1S)), num1I = stoi(num1.substr(num1S+1)),
        num2R = stoi(num2.substr(0, num2S)), num2I = stoi(num2.substr(num2S+1));
    // int numR = num1R * num2R - num1I * num2I, numI = num1R * num2I + num2R * num1I;
    return to_string(num1R * num2R - num1I * num2I) + "+" + to_string(num1R * num2I + num2R * num1I) + "i";
}

int main(){
    string num1 = "1+-1i", num2 = "1+-1i";
    cout << complexNumberMultiply(num1, num2) << endl;
    return 0;
}
